package cn.lu.joke.adapter;

import android.graphics.Color;
import android.support.annotation.Nullable;

import cn.lu.joke.adapter.decoration.Divider;
import cn.lu.joke.adapter.decoration.DividerBuilder;
import cn.lu.joke.adapter.decoration.ItemDividerDecoration;

public class Grid3DividerDecoration extends GridDividerDecoration {

    @Override
    public int getSpanCount() {
        return 3;
    }

    @Nullable
    @Override
    public Divider getDivider(int itemPosition, int itemCount) {
        if (hasTitle) {
            return getHasTitleDivider(itemPosition);
        } else {
            return getDefaultDivider(itemPosition);
        }
    }

    private Divider getDefaultDivider(int itemPosition) {
        switch (itemPosition) {
            case 0:
            case 1:
                return new DividerBuilder()
                        .setRightSideLine(true, color, width, 0, 0)
                        .create();
            case 2:
                return null;
        }
        switch (itemPosition % spanCount) {
            case 0:
            case 1:
                return new DividerBuilder()
                        .setTopSideLine(true, color, width, 0, 0)
                        .setRightSideLine(true, color, width, 0, 0)
                        .create();
            case 2:
                return new DividerBuilder()
                        .setTopSideLine(true, color, width, 0, 0)
                        .create();
        }

        return null;
    }

    private Divider getHasTitleDivider(int itemPosition) {
        switch (itemPosition) {
            case 0:
            case 3:
                return null;
            case 1:
            case 2:
                return new DividerBuilder()
                        .setRightSideLine(true, color, width, 0, 0)
                        .create();
        }

        switch (itemPosition % spanCount) {
            case 1:
            case 2:
                return new DividerBuilder()
                        .setTopSideLine(true, color, width, 0, 0)
                        .setRightSideLine(true, color, width, 0, 0)
                        .create();
            case 0:
                return new DividerBuilder()
                        .setTopSideLine(true, color, width, 0, 0)
                        .create();
        }

        return null;
    }
}
